package com.tbit.uqbike.service.business.impl;

import com.alibaba.fastjson.JSONObject;
import com.tbit.uqbike.object.pojo.OperateLog;
import com.tbit.uqbike.service.business.OperateLogService;
import com.tbit.uqbike.webmanager.dao.log.OperateLogDao;
import com.tbit.uqbike.webmanager.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户操作日志(OperateLog)表服务实现类
 *
 * @author jing
 * @since 2021-04-07 10:04:07
 */
@Service("operateLogService")
public class OperateLogServiceImpl implements OperateLogService {
    @Autowired
    private OperateLogDao operateLogDao;


    /**
     * 查询用户操作日志
     *
     * @param type 用户操作日志ID
     * @return 用户操作日志
     */
    @Override
    public OperateLog selectOperateLogById(Integer type) {
        return operateLogDao.selectOperateLogById(type);
    }

    /**
     * 查询用户操作日志列表
     *
     * @param operateLog 用户操作日志
     * @return 用户操作日志
     */
    @Override
    public List<OperateLog> selectOperateLogList(OperateLog operateLog) {
        List<OperateLog> operateLogs = operateLogDao.selectOperateLogList(operateLog);
        operateLogs.forEach(operateLog1 -> {
            JSONObject jsonObject = JSONObject.parseObject(operateLog1.getParam());
            if (StringUtils.isNotNull(jsonObject.get("operaPsw"))) {
                jsonObject.remove("operaPsw");
            }
            if (StringUtils.isNotNull(jsonObject.get("secret"))) {
                jsonObject.remove("secret");
            }
            if (StringUtils.isNotNull(jsonObject.get("code"))) {
                jsonObject.remove("code");
            }
            operateLog1.setParam(jsonObject.toJSONString());
        });
        return operateLogs;
    }

    /**
     * 新增用户操作日志
     *
     * @param operateLog 用户操作日志
     * @return 结果
     */
    @Override
    public int insertOperateLog(OperateLog operateLog) {
        return operateLogDao.insertOperateLog(operateLog);
    }

    /**
     * 修改用户操作日志
     *
     * @param operateLog 用户操作日志
     * @return 结果
     */
    @Override
    public int updateOperateLog(OperateLog operateLog) {
        return operateLogDao.updateOperateLog(operateLog);
    }

    /**
     * 批量删除用户操作日志
     *
     * @param types 需要删除的用户操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperateLogByIds(Integer[] types) {
        return operateLogDao.deleteOperateLogByIds(types);
    }

    /**
     * 删除用户操作日志信息
     *
     * @param type 用户操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperateLogById(Integer type) {
        return operateLogDao.deleteOperateLogById(type);
    }
}